<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>  
  var relativeSortArray = function (arr1, arr2) {
            let arr = []
            for (let i = 0; i < arr2.length; i++) {
                if (arr1.indexOf(arr2[i]) > -1) {
                    arr.push(arr2[i])
                    arr1.splice(arr1.indexOf(arr2[i]), 1)
                    i--;
                }
            }
            arr1.sort(function (a, b) {
                return a - b
            })
            return arr.concat(arr1)
        };
        console.log(relativeSortArray( [2,3,1,3,2,4,6,7,9,2,19],[2,1,4,3,9,6]));
  </script>
</body>
</html>